package com.dinzeer.resonantisshelomoh.item;

import com.dinzeer.legendreliclib.lib.util.text.AdvancedGradientTextHelper;
import com.dinzeer.legendreliclib.lib.util.text.ColorPreset;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import mods.flammpfeil.slashblade.item.SwordType;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.EnumSet;
import java.util.List;

public class ItemSolmenBlade extends ItemSlashBlade {
    public ItemSolmenBlade(Tier tier,Properties builder) {
        super(tier, 5, 5, builder);
    }


    @Override
    public void appendSlashArt(ItemStack stack, List<Component> tooltip, @NotNull ISlashBladeState s) {
        EnumSet<SwordType> swordType = SwordType.from(stack);
        if (swordType.contains(SwordType.BEWITCHED) && !swordType.contains(SwordType.SEALED)) {
            String originalName = Component.translatable("slashblade.tooltip.slash_art", new Object[]{s.getSlashArts().getDescription()}).getString();
            ColorPreset colorPreset = ColorPreset.MONOCHROME_GRAY;
            AdvancedGradientTextHelper.GradientMode gradientMode = AdvancedGradientTextHelper.GradientMode.FLOW;
            if (this.getName(stack).getString().equals( Component.translatable("item.resonantisshelomoh.reverse_solomon").getString())){
                colorPreset=ColorPreset.RED_EMBER;
                gradientMode= AdvancedGradientTextHelper.GradientMode.FLOW;
            }
            if (this.getName(stack).getString().equals( Component.translatable("item.resonantisshelomoh.solomon").getString())){
                colorPreset=ColorPreset.CYAN_AQUA;
                gradientMode= AdvancedGradientTextHelper.GradientMode.PULSE;
            }
            tooltip.add(AdvancedGradientTextHelper.createGradientText(originalName, colorPreset, gradientMode));
        }

    }

    @Override
    public void appendRefineCount(List<Component> tooltip, @NotNull ItemStack stack) {
        CompoundTag tag = stack.getOrCreateTag();
        if (tag.contains("bladeState")) {
            int refine = tag.getCompound("bladeState").getInt("RepairCounter");

            String originalName =Component.translatable("slashblade.tooltip.refine", new Object[]{refine}).getString();
            ColorPreset colorPreset = ColorPreset.MONOCHROME_GRAY;
            AdvancedGradientTextHelper.GradientMode gradientMode = AdvancedGradientTextHelper.GradientMode.FLOW;
            if (this.getName(stack).getString().equals( Component.translatable("item.resonantisshelomoh.reverse_solomon").getString())){
                colorPreset=ColorPreset.RED_EMBER;
                gradientMode= AdvancedGradientTextHelper.GradientMode.FLOW;
            }
            if (this.getName(stack).getString().equals( Component.translatable("item.resonantisshelomoh.solomon").getString())){
                colorPreset=ColorPreset.CYAN_AQUA;
                gradientMode= AdvancedGradientTextHelper.GradientMode.PULSE;
            }
            tooltip.add(AdvancedGradientTextHelper.createGradientText(originalName, colorPreset, gradientMode));
        }
    }

    @Override
    public void appendProudSoulCount(List<Component> tooltip, @NotNull ItemStack stack) {
        CompoundTag tag = stack.getOrCreateTag();
        if (tag.contains("bladeState")) {
            int proudsoul = tag.getCompound("bladeState").getInt("proudSoul");


                String originalName =Component.translatable("slashblade.tooltip.proud_soul", new Object[]{proudsoul}).getString();

                ColorPreset colorPreset = ColorPreset.MONOCHROME_GRAY;
                AdvancedGradientTextHelper.GradientMode gradientMode = AdvancedGradientTextHelper.GradientMode.FLOW;
                if (this.getName(stack).getString().equals( Component.translatable("item.resonantisshelomoh.reverse_solomon").getString())){
                    colorPreset=ColorPreset.RED_EMBER;
                    gradientMode= AdvancedGradientTextHelper.GradientMode.FLOW;
                }
                if (this.getName(stack).getString().equals( Component.translatable("item.resonantisshelomoh.solomon").getString())){
                    colorPreset=ColorPreset.CYAN_AQUA;
                    gradientMode= AdvancedGradientTextHelper.GradientMode.PULSE;
                }
                tooltip.add(AdvancedGradientTextHelper.createGradientText(originalName, colorPreset, gradientMode));


        }
    }

    @Override
    public void appendKillCount(List<Component> tooltip, @NotNull ItemStack stack) {
        CompoundTag tag = stack.getOrCreateTag();
        if (tag.contains("bladeState")) {
            int killCount = tag.getCompound("bladeState").getInt("killCount");
            if (killCount > 0) {
                String originalName =Component.translatable("slashblade.tooltip.killcount", new Object[]{killCount}).getString();
                ColorPreset colorPreset = ColorPreset.MONOCHROME_GRAY;
                AdvancedGradientTextHelper.GradientMode gradientMode = AdvancedGradientTextHelper.GradientMode.FLOW;
                if (this.getName(stack).getString().equals( Component.translatable("item.resonantisshelomoh.reverse_solomon").getString())){
                    colorPreset=ColorPreset.RED_EMBER;
                    gradientMode= AdvancedGradientTextHelper.GradientMode.FLOW;
                }
                if (this.getName(stack).getString().equals( Component.translatable("item.resonantisshelomoh.solomon").getString())){
                    colorPreset=ColorPreset.CYAN_AQUA;
                    gradientMode= AdvancedGradientTextHelper.GradientMode.PULSE;
                }
                tooltip.add(AdvancedGradientTextHelper.createGradientText(originalName, colorPreset, gradientMode));

            }

        }
    }
    @Override
    public Component getName(ItemStack stack) {
        String originalName = super.getName(stack).getString();

        ColorPreset colorPreset = ColorPreset.MONOCHROME_GRAY;
        AdvancedGradientTextHelper.GradientMode gradientMode = AdvancedGradientTextHelper.GradientMode.FLOW;

        if (originalName.equals( Component.translatable("item.resonantisshelomoh.reverse_solomon").getString())){
            colorPreset=ColorPreset.RED_EMBER;
            gradientMode= AdvancedGradientTextHelper.GradientMode.FLOW;
        }
        if (originalName.equals( Component.translatable("item.resonantisshelomoh.solomon").getString())){
            colorPreset=ColorPreset.CYAN_AQUA;
            gradientMode= AdvancedGradientTextHelper.GradientMode.PULSE;
        }
        Component newName= AdvancedGradientTextHelper.createGradientText(originalName, colorPreset, gradientMode);
        return newName;
    }
    @Override
    public void appendSpecialEffects(List<Component> tooltip, @NotNull ISlashBladeState s) {
        if (!s.getSpecialEffects().isEmpty()) {
            Minecraft mcinstance = Minecraft.getInstance();
            Player player = mcinstance.player;
            s.getSpecialEffects().forEach((se) -> {


                boolean showingLevel = SpecialEffect.getRequestLevel(se) > 0;
                String originalName =
                        Component.translatable("slashblade.tooltip.special_effect",
                                new Object[]{SpecialEffect.getDescription(se),
                                        Component.literal(showingLevel ? String.valueOf(SpecialEffect.getRequestLevel(se)) : "")} ).getString();
                ColorPreset colorPreset = ColorPreset.MONOCHROME_GRAY;
                AdvancedGradientTextHelper.GradientMode gradientMode = AdvancedGradientTextHelper.GradientMode.FLOW;
                if (Component.translatable(s.getTranslationKey()).getString().equals( Component.translatable("item.resonantisshelomoh.reverse_solomon").getString())){
                    colorPreset=ColorPreset.RED_EMBER;
                    gradientMode= AdvancedGradientTextHelper.GradientMode.FLOW;
                }
                if (Component.translatable(s.getTranslationKey()).getString().equals( Component.translatable("item.resonantisshelomoh.solomon").getString())){
                    colorPreset=ColorPreset.CYAN_AQUA;
                    gradientMode= AdvancedGradientTextHelper.GradientMode.PULSE;
                }
                tooltip.add(AdvancedGradientTextHelper.createGradientText(originalName, colorPreset, gradientMode));

        });
    }
    }






}
